package com.tenglong.teacher.ui.adapter.viewholder;

import android.view.View;
import android.widget.TextView;

import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.BaseHomeWorkInfo;
import com.tenglong.teacher.data.resultInfo.HistoryHomeWorkOutsideInfo;
import com.tenglong.teacher.ui.adapter.HomeWorkAdapter;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;

/**
 * @author hdx on 2019/3/1.
 */
public class HistoryHomeworkOutsideViewHolder extends BaseViewHolder<BaseHomeWorkInfo> {
    private HomeWorkAdapter.HomeworkListener listener;
    private TextView classes,tip_homework;
    private HistoryHomeWorkOutsideInfo data;
    private boolean isOld=true;
    public HistoryHomeworkOutsideViewHolder(View itemView) {
        super(itemView);
        initView();
        setLisnters();
    }

    public HistoryHomeworkOutsideViewHolder(View itemView, HomeWorkAdapter.HomeworkListener listener) {
        this(itemView);
        this.listener = listener;
    }

    private void setLisnters() {
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.onClickHistoryItemListener(getLayoutPosition());
                }
            }
        });
    }

    public boolean isOld() {
        return isOld;
    }

    public void setOld(boolean old) {
        this.isOld = old;
    }

    private void initView() {
        classes = itemView.findViewById(R.id.classes);
        tip_homework = itemView.findViewById(R.id.tip_homework);
    }

    @Override
    public void setLayoutInfo(BaseHomeWorkInfo info) {
        data = (HistoryHomeWorkOutsideInfo) info;
        classes.setText(data.name);
        if(isOld()){
            tip_homework.setBackgroundResource(R.drawable.history_homework_left_icon_shape);
        }else{
            tip_homework.setBackgroundResource(R.drawable.current_homework_left_icon_shape);
        }
    }
}
